import time
from celery import Celery
from Factory.video_template_factory import TemplateFactory
from config import config

broker = config.CELERY_BROKER_URL  # 任务储存
backend = config.CELERY_RESULT_BACKEND

app = Celery('tasks', broker=broker, backend=backend)


# 测试任务
@app.task
def add(x, y):
    return x + y


@app.task
def addTemplateViewGenerateTask(template_type, video_info):
    template = TemplateFactory.get_template(template_type)
    template.generate(video_info)
    # 睡眠20秒
    time.sleep(20)
    return video_info
